<?php

class shopModel extends commonModel {

    public function __construct() {
        $this->initialDB();
    }

    //获取xd_log的所有标题名称（page）
    public function getLogPage() {
        //$table="xd_log";
        $sql = " SELECT * FROM `logdata` WHERE `isdeleted` = 0 GROUP BY `page` order by CONVERT(`page` USING utf8) DESC";
        //echo $sql;
        $this->db->setStatement($sql);
        $result= $this->db->execute();
        $result=$this->getArray($result);
        //var_dump($result);
        //die;
        return $result;

    }

    /**
     * @param $status 订单状态
     * @return mixed 数量
     */
    public function GetOrderCount($status){
        $sql = " SELECT count(*) as num FROM orders as o left join xd_store as s ON o.shop_no = s.store_id WHERE o.isdeleted = 0 AND o.status = $status AND s.store_id = ".$_SESSION['zp_store']['store_code'];
        $this->db->setStatement($sql);
        $result= $this->db->execute();
        $result=$this->getArray($result);
        return $result[0]['num'];
    }

    /**
     * @return mixed 返回异常订单数量
     */
    public function GetErrorOrderCount(){
        $where = 'o.isdeleted = 0 AND (o.status=6 OR o.status = 7) AND op.express_type = "self"';
        $sql = "SELECT count(*) as num  FROM orders as o left join xd_store as s ON s.store_id = o.shop_no left join orders_express as op ON o.ph_no = op.ph_no WHERE $where AND s.store_id = ".$_SESSION['zp_store']['store_code'];
        $this->db->setStatement($sql);
        $result= $this->db->execute();
        $result=$this->getArray($result);
        return $result[0]['num'];
    }

    /**
     * @return mixed 返回骑手数量
     */
    public function GetRidersCount(){
        $sql = "SELECT count(*) as num  FROM riders as r LEFT JOIN xd_store as t ON t.store_id = r.service_shop_no where (r.status = 1 OR r.status = 4) AND r.isdeleted = 0  AND  t.store_id = ".$_SESSION['zp_store']['store_code'];
        $this->db->setStatement($sql);
        $result= $this->db->execute();
        $result=$this->getArray($result);
        return $result[0]['num'];
    }

}
